package HuaweiOD;

import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ABR车路协同场景 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        Matcher matcher = Pattern.compile("A=\\{(.+)},B=\\{(.+)},R=(.+)").matcher(str);
        
        if (matcher.matches()){
            int[] A = Arrays.stream(matcher.group(1).split(",")).mapToInt(Integer::parseInt).toArray();
            int[] B = Arrays.stream(matcher.group(2).split(",")).mapToInt(Integer::parseInt).toArray();
            int R = Integer.parseInt(matcher.group(3));
            System.out.println(solve(A, B, R));
        }
    }
    
    public static String solve(int[] A, int[] B, int R){
        
        StringBuilder sb = new StringBuilder();
        
        for (int a : A) {
            boolean jdg = true;
            for (int b : B) {
                if (b < a) continue;
                if (b - a <= R || jdg){
                    sb.append("(").append(a).append(",").append(b).append(")");
                    jdg = false;
                }else {
                    break;
                }
            }
        }
        
        return sb.toString();
    }
}
